package com.zmn.oms.dubbo.impl.zmn.third.jddj;

import org.apache.dubbo.config.annotation.Service;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.dubbo.interfaces.zmn.third.jddj.JddjRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.third.jddj.service.JddjService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author xiewenbing
 * @date:2021/03/18 11:45 上午
 * description: 京东到家的H5页面接口，用来验证核销码等
 */
@Slf4j
@Api(value = "京东到家H5接口", tags = {"京东到家H5接口"})
@Service(loadbalance = "roundrobin", timeout = 5000, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class JddjRemoteServiceImpl implements JddjRemoteService {

    @Autowired
    private JddjService jddjService;

    /**
     * 京东渠道验证核销码
     *
     * @param orderId
     * @param code
     * @return
     */
    @Override
    @ApiOperation(value = "验证核销码", response = ResponseDTO.class)
    public ResponseDTO validateVerificationCode(@ApiParam(value = "订单id") @NotNull(message = "订单ID不能为Null") Long orderId,
                                                @ApiParam(value = "核销码") @NotBlank(message = "核销码不能为空") String code) {

        try {
            log.info("接口<JddjRemoteService.validateVerificationCode>收到的入参, orderId:{},code:{}", orderId, code);
            jddjService.validateVerificationCode(orderId, code);
        } catch (OmsBaseException exception) {
            return ResponseDTO.fail(exception.getMessage());
        }

        return ResponseDTO.success();
    }


    /**
     * 京东渠道读取核销码
     *
     * @param orderId
     * @return
     */
    @Override
    @ApiOperation(value = "读取核销码", response = ResponseDTO.class)
    public ResponseDTO<String> getVerificationCode(@ApiParam(value = "订单id") @NotNull(message = "订单ID不能为Null") Long orderId) {

        try {
            String vCode = jddjService.getVerificationCode(orderId);
            return ResponseDTO.success(vCode);

        } catch (OmsBaseException exception) {
            return ResponseDTO.fail(exception.getMessage());
        }
    }


    @Override
    @ApiOperation(value = "验证核销码，访问cds", response = ResponseDTO.class)
    public ResponseDTO validateVerificationCodeV2(Long orderId, String code) {
        try {
            log.info("接口<JddjRemoteService.validateVerificationCodeV2>收到的入参, orderId:{},code:{}", orderId, code);
            jddjService.validateVerificationCodeV2(orderId, code);
        } catch (OmsBaseException exception) {
            return ResponseDTO.fail(exception.getMessage());
        }

        return ResponseDTO.success();
    }


}
